home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / System Messages / Clock-2 / README.Clock < prev   
Encoding:
Text File  |  1994-02-28  |  1.9 KB  |  52 lines  |  [TEXT/ttxt]

  1. Clock
  2. Copyright © 1993, 1994 by Apple Computer, Inc.  All rights reserved.
  3. by Maurice Sharp
  4.  
  5. Welcome to Wiggy Clock!
  6.  
  7. This is a very simple bit of code that shows a couple of things
  8.     idle scripts
  9.     time formats and fun
  10.  
  11. All the work is done in the protoStaticText item, so lets take a tour....
  12.  
  13. •viewBounds
  14.  
  15. Set them this way to get nice centered justification, also set the height
  16. dynamically in the viewSetupFormScript()
  17.  
  18. •viewSetupDoneScript()
  19.  
  20. This is where I set up the idle task. First I setup an initial string (might as
  21. well use viewIdleScript(), otherwise I would just end up duplicating code).
  22.  
  23. Then call the SetupIdle() call and pass it 1000 milliseconds (1 second). This
  24. says, call my viewIdleScript() in 1 second. (NOTE: pass 0 or NIL to disable the
  25. idle behavior).
  26.  
  27. •viewIdleScript
  28.  
  29. First, a constant used to specify a time specification (really). This is used by
  30. the TimeStr() function (and also by ShortDateStr() and LongDateStr()). Take a
  31. look at those manuals, chapter 18...
  32.  
  33. First I figure out the current seconds. The Time() function returns minutes
  34. since January 1 1904, TimeInSeconds() returns seconds since January 1 1993 (note
  35. the different years). So I do a bit of trickery to get the current seconds (well
  36. not much trickery). And remember, the string needs to always have 2 digits, so
  37. pad it if needed.
  38.  
  39. Next, set my text value, simple huh? This SetValue call makes sure the text is
  40. updated on the display.
  41.  
  42. Finally, return 1000 milliseconds so that the script will get called the next
  43. second. Is this easy or what...
  44.  
  45. DANGER WILL ROBINSON... Remember that idle scripts are potential battery sinks.
  46. Just leave that sucker going and watch the battery meter drop... I should really
  47. be doing a minute (60000 millisecond) update to be nice. Then I could just use
  48. Time(), gosh Batman, it could have been easier, but then this would not be DTS,
  49. and I would not be....
  50.  
  51. Dr. What
  52.